

var $, form,tree;
layui.use(["form",'tree', 'util'], function () {
    $ = layui.$
        , form = layui.form, tree = layui.tree;


    $.ajax({
        url:"/admin/authrule/lists_json",
        type:'POST',
        success:function(result){
            //基本演示
            tree.render({
                elem: '#test12'
                ,data: result.data
                ,showCheckbox: true  //是否显示复选框
                ,id: 'demoId1'
                ,isJump: false //是否允许点击节点时弹出新窗口跳转
                /*,click: function(obj){
                    var data = obj.data;  //获取当前点击的节点数据
                    layer.msg('状态：'+ obj.state + '<br>节点数据：' + JSON.stringify(data));
                }*/
            });



            var id = getPar('id');
            if(id>0){
                layer.load(1)

                $.ajax({
                    url: './info',
                    type: 'GET',
                    data: {id: id},
                    success: function (result) {
                        if (result.code == 200) {
                            //layuiadmin-form-role 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                            //给表单赋值
                            form.val("layuiadmin-form-role",result.data);
                            var rules = result.data.rules.split(',').map(item => {
                                return +item;
                            });
                            tree.setChecked('demoId1',rules); //勾选指定节点

                        } else {
                            layer.msg(result.message)
                        }
                        layer.closeAll();
                    }
                });
            }


        }});








    
})